using Nop.Core.Infrastructure;
using Nop.Web.Framework.Localization;
using Nop.Web.Framework.Mvc.Routes;
using System.Web.Mvc;
using System.Web.Routing;

namespace SpotsHub.Gateway
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("favicon.ico");
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //Default
            routes.MapRoute("Gateway",
                            "Gateway",
                            new { controller = "Home", action = "Index" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            routes.MapRoute("HomePage",
                            "",
                            new { controller = "Home", action = "Index", area = "Commerce" },
                            new[] { "Nop.Web.Controllers" });

            routes.MapRoute("SwitchHome",
                            "SwitchHome/{beta}",
                            new { controller = "Home", action = "SwitchHome" },
                            new { beta = "^(?i:true|false)$" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            //Pages
            routes.MapRoute("ShippingRegulation",
                            "shipping-regulation",
                            new { controller = "Home", action = "ShippingRegulation" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("OnlineShopping",
                            "online-shopping",
                            new { controller = "Home", action = "OnlineShopping" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("ContactSpotsHub",
                            "contact-spotshub",
                            new { controller = "Home", action = "ContactSpotsHub" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("Testimonial",
                            "testimonial",
                            new { controller = "Home", action = "Testimonial" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("TermsAndConditions",
                            "terms-and-conditions",
                            new { controller = "Home", action = "TermsAndConditions"},
                            new[] { "Logistics.Web.Controllers" });
            routes.MapRoute("Disclaimer",
                            "disclaimer",
                            new { controller = "Home", action = "Disclaimer" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("PrivacyPolicy",
                            "privacy-policy",
                            new { controller = "Home", action = "PrivacyPolicy" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("Career",
                            "career",
                            new { controller = "Home", action = "Career" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("Press",
                            "press",
                            new { controller = "Home", action = "Press" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("ClubMembership",
                            "aboutclubmembership",
                            new { controller = "Home", action = "AboutClubMembership" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("QuestionsAndAnswers",
                            "Q-and-A",
                            new { controller = "Home", action = "QuestionsAndAnswers" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("OperatingHours",
                            "operating-hours",
                            new { controller = "Home", action = "OperatingHours" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("FuelSurcharge",
                            "fuelsurcharge",
                            new { controller = "Home", action = "FuelSurcharge" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("AboutExpress",
                            "aboutexpress",
                            new { controller = "Home", action = "AboutExpress" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("SellOnline",
                            "sell-online",
                            new { controller = "Home", action = "SellOnline" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("ExpeditedShippingExperienceEvent",
                            "expedited-shipping-experience-event",
                            new { controller = "Home", action = "ExpeditedShippingExperienceEvent" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("SellWithUs",
                            "sellwithus",
                            new { controller = "Message", action = "SellWithUs" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("SneakPeek",
                            "sneakpeek",
                            new { controller = "Message", action = "SneakPeek" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            // Customer Login/Register
            routes.MapLocalizedRoute("Register",
                            "register",
                            new { controller = "Customer", action = "Register" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("RegisterResult",
                            "registerresult/{resultId}",
                            new { controller = "Customer", action = "RegisterResult" },
                            new { resultId = @"\d+" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("RegisterSuccess",
                            "registersuccess",
                            new { controller = "Customer", action = "RegisterSuccess" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CheckUsernameAvailability",
                            "checkusernameavailability",
                            new { controller = "Customer", action = "CheckUsernameAvailability" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("Login",
                            "login",
                            new { controller = "Customer", action = "Login" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("LoginCheckoutAsGuest",
                            "login/checkoutasguest",
                            new { controller = "Customer", action = "Login", checkoutAsGuest = true },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("Logout",
                            "logout",
                            new { controller = "Customer", action = "Logout" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            // Customer Password
            routes.MapLocalizedRoute("PasswordRecovery",
                            "passwordrecovery",
                            new { controller = "Customer", action = "PasswordRecovery" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("PasswordRecoveryConfirm",
                            "passwordrecovery/confirm",
                            new { controller = "Customer", action = "PasswordRecoveryConfirm" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            // Customer Misc.
            routes.MapLocalizedRoute("DeleteBackInStockSubscription",
                            "backinstocksubscribe/delete/{subscriptionId}",
                            new { controller = "Customer", action = "DeleteBackInStockSubscription" },
                            new { subscriptionId = @"\d+" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("DownloadUserAgreement",
                            "useragreement/{opvid}",
                            new { controller = "Customer", action = "UserAgreement" },
                            new { opvid = new GuidConstraint(false) },
                            new[] { "SpotsHub.Gateway.Controllers" });
            //changeCurrency
            routes.MapLocalizedRoute("ChangeCustomerCurrency", "customer/changecurrency",
                            new { controller = "Customer", action = "ChangeCustomerCurrency" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            //getAllCurrency
            routes.MapLocalizedRoute("GetAllCurrency", 
                            "customer/getallcurrency",
                             new { controller = "Customer", action = "GetAllCurrency" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            // MyHUB Functions
            routes.MapLocalizedRoute("CustomerMyAccount",
                            "customer/myaccount",
                            new { controller = "Customer", action = "MyAccount" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerInfo",
                            "customer/info",
                            new { controller = "Customer", action = "Info" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddresses",
                            "customer/addresses",
                            new { controller = "Customer", action = "Addresses" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerOrders",
                            "customer/orders",
                            new { controller = "Customer", action = "Orders" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerTracking",
                            "customer/tracking",
                            new { controller = "Customer", action = "Tracking" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerCalculateShipmentRate",
                            "customer/calculaterate",
                            new { controller = "Customer", action = "CalculateRate" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerInvoices",
                            "customer/invoices",
                            new { controller = "Customer", action = "Invoices" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerInvoicesList",
                            "customer/invoiceslist",
                            new { controller = "Customer", action = "InvoicesList" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerEmailPreference",
                            "customer/emailpreference",
                            new { controller = "Customer", action = "EmailPreference" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerReturnRequests",
                            "customer/returnrequests",
                            new { controller = "Customer", action = "ReturnRequests" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerReturnRequestsList",
                            "customer/returnrequestslist",
                            new { controller = "Customer", action = "ReturnRequestsList" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerDownloadableProducts",
                            "customer/downloadableproducts",
                            new { controller = "Customer", action = "DownloadableProducts" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerBackInStockSubscriptions",
                            "customer/backinstocksubscriptions",
                            new { controller = "Customer", action = "BackInStockSubscriptions" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerBackInStockSubscriptionsPaged",
                            "customer/backinstocksubscriptions/{page}",
                            new { controller = "Customer", action = "BackInStockSubscriptions", page = UrlParameter.Optional },
                            new { page = @"\d+" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerRewardPoints",
                            "customer/rewardpoints",
                            new { controller = "Customer", action = "RewardPoints" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerChangePassword",
                            "customer/changepassword",
                            new { controller = "Customer", action = "ChangePassword" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerMembership",
                            "customer/membership",
                            new { controller = "Customer", action = "Membership" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerSettings",
                            "customer/settings",
                            new { controller = "Customer", action = "Settings" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            routes.MapLocalizedRoute("CustomerMembershipPaymentMethod",
                            "customer/paymentmethod",
                            new { controller = "Customer", action = "PaymentMethod" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            routes.MapLocalizedRoute("CustomerMembershipSavePaymentMethod",
                            "customer/savepaymentmethod",
                            new { controller = "Customer", action = "SavePaymentMethod" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            routes.MapLocalizedRoute("CustomerMembershipSavePaymentInfo",
                            "customer/savepaymentinfo",
                            new { controller = "Customer", action = "SavePaymentInfo" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            routes.MapLocalizedRoute("CustomerAvatar",
                            "customer/avatar",
                            new { controller = "Customer", action = "Avatar" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("AccountActivation",
                            "customer/activation",
                            new { controller = "Customer", action = "AccountActivation" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("DownloadInvoice",
                            "customer/downloadinvoice/{id}",
                            new { controller = "Customer", action = "DownloadInvoice" },
                            new { id = @"\d+" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("TrackingPackageList",
                            "customer/tracking/trackingpackagelist",
                            new { controller = "Customer", action = "TrackingPackageList" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("OrderList",
                            "customer/order/orderlist",
                            new { controller = "Customer", action = "OrderList" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            // Addresses
            routes.MapLocalizedRoute("CustomerAddressDelete",
                            "customer/addresses/delete/{addressId}",
                            new { controller = "Customer", action = "AddressDelete" },
                            new { addressId = @"\d+" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddressEdit",
                            "customer/addresses/edit/{addressId}",
                            new { controller = "Customer", action = "AddressEdit" },
                            new { addressId = @"\d+" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddressAdd",
                            "customer/addresses/add",
                            new { controller = "Customer", action = "AddressAdd" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddressAddInPage",
                            "customer/addresses/add/inpage",
                            new { controller = "Customer", action = "AddressAddInPage" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddressEditInPage",
                            "customer/addresses/edit/inpage",
                            new { controller = "Customer", action = "AddressEditInPage" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddressDeleteInPage",
                            "customer/addresses/delete/inpage/{addressId}",
                            new { controller = "Customer", action = "AddressDeleteInPage" },
                            new { addressId = @"\d+" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddressesLoad",
                            "customer/addresses/load",
                            new { controller = "Customer", action = "AddressesLoad" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapLocalizedRoute("CustomerAddressSetDefault",
                            "customer/addresses/setdefault",
                            new { controller = "Customer", action = "AddressSetDefault" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            // Change address in customer controller
            routes.MapLocalizedRoute("AddressChange",
                            "customer/AddressEditChange/{addressId}/{shipmentId}/{addressType}",
                            new { area = "Commerce", controller = "Customer", action = "AddressEditChange" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("NonMemberPaymentInfo",
                           "customer/PaymentInfo",
                           new { controller = "Customer", action = "PaymentInfo" },
                           new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("NonMemberPaymentInfoRedirect",
                           "customer/PaymentInfoRedirect",
                           new { controller = "Customer", action = "PaymentInfoRedirect" },
                           new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("NonMemberAddressEditChange",
                           "customer/AddressEditChange",
                           new { controller = "Customer", action = "AddressEditChange" },
                           new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("AddressSelect",
                          "customer/AddressSelect",
                          new { controller = "Customer", action = "AddressSelect" },
                          new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("RouteCancelPackage",
                          "customer/CancelPackage",
                          new { controller = "Customer", action = "CancelPackage" },
                          new[] { "SpotsHub.Gateway.Controllers" });
            routes.MapRoute("CustomerUpdateShipment",
                          "customer/UpdateShipment",
                          new { controller = "Customer", action = "UpdateShipment" },
                          new[] { "SpotsHub.Gateway.Controllers" });

            //KeepAlive
            routes.MapRoute("KeepAlive",
                            "KeepAlive",
                            new { controller = "Home", action = "KeepAlive" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            // Hard coded landing page. To do: create landing page templates like topic
            routes.MapRoute("BerlinettaFerrariLandingPage",
                            "f12-berlinetta-ferrari-info",
                            new { controller = "Home", action = "BerlinettaFerrariLandingPage" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            //OrderLogistics
            routes.MapRoute("OrderLogistics",
                            "orderlogistics",
                            new { controller = "Home", action = "OrderLogistics" },
                            new[] { "SpotsHub.Gateway.Controllers" });

            routes.MapRoute("Common",
                "common/{action}",
                new { controller = "Common", action = "" },
                new[] { "SpotsHub.Gateway.Controllers" });

            //Messages
            routes.MapLocalizedRoute("RenderMessages",
                            "common/rendermessages",
                            new { controller = "Common", action = "RenderMessages" },
                            new[] { "SpotsHub.Gateway.Controllers" });
            //ExternalMethods
            routes.MapLocalizedRoute("ExternalMethods",
                "ExternalAuthentication/ExternalMethods",
                new { controller = "ExternalAuthentication", action = "ExternalMethods" },
                new[] { "SpotsHub.Gateway.Controllers" });

            //register all routes (plugins, etc)
            var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>();
            routePublisher.RegisterRoutes(routes);

            //Default: redirect to home when flows here
            routes.MapRoute("Default",
                "{action}",
                new { controller = "Home", action = "Index" },
                new[] { "SpotsHub.Gateway.Controllers" });
        }
    }
}